
<h1><span class="yiyi-st" id="yiyi-12">numpy.core.records.fromrecords</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.core.records.fromrecords.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.core.records.fromrecords.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.core.records.fromrecords"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">numpy.core.records.</code><code class="descname">fromrecords</code><span class="sig-paren">(</span><em>recList</em>, <em>dtype=None</em>, <em>shape=None</em>, <em>formats=None</em>, <em>names=None</em>, <em>titles=None</em>, <em>aligned=False</em>, <em>byteorder=None</em><span class="sig-paren">)</span><a class="reference external" href="http://github.com/numpy/numpy/blob/v1.11.3/numpy/core/records.py#L628-L689"><span class="viewcode-link">[source]</span></a></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-14">从文本形式的记录列表创建一个recarray</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-15">同一字段中的数据可以是异构的，它们将被提升到最高的数据类型。</span><span class="yiyi-st" id="yiyi-16">此方法用于创建较小的记录数组。</span><span class="yiyi-st" id="yiyi-17">如果用于创建没有格式定义的大数组</span></p>
<p><span class="yiyi-st" id="yiyi-18">r = fromrecords（[（2,3，，abc&apos;）] * 100000）</span></p>
<p><span class="yiyi-st" id="yiyi-19">它可以很慢。</span></p>
<p><span class="yiyi-st" id="yiyi-20">如果格式为无，则会自动检测格式。</span><span class="yiyi-st" id="yiyi-21">使用元组列表而不是列表列表，以便更快地处理。</span></p>
</div></blockquote>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">records</span><span class="o">.</span><span class="n">fromrecords</span><span class="p">([(</span><span class="mi">456</span><span class="p">,</span><span class="s1">&apos;dbe&apos;</span><span class="p">,</span><span class="mf">1.2</span><span class="p">),(</span><span class="mi">2</span><span class="p">,</span><span class="s1">&apos;de&apos;</span><span class="p">,</span><span class="mf">1.3</span><span class="p">)],</span>
<span class="gp">... </span><span class="n">names</span><span class="o">=</span><span class="s1">&apos;col1,col2,col3&apos;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">r</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="go">(456, &apos;dbe&apos;, 1.2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">col1</span>
<span class="go">array([456,   2])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span><span class="o">.</span><span class="n">col2</span>
<span class="go">array([&apos;dbe&apos;, &apos;de&apos;],</span>
<span class="go">      dtype=&apos;|S3&apos;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pickle</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pickle</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">pickle</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">r</span><span class="p">)))</span>
<span class="go">[(456, &apos;dbe&apos;, 1.2) (2, &apos;de&apos;, 1.3)]</span>
</pre></div>
</div>
</dd></dl>
